package com.taotie.thetoolofgluttony.common;

import java.io.IOException;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.resources.I18n;

public class GenerateGui extends GuiScreen {
	private GuiScreen parentScreen;
	private GuiTextField field1;
	private GuiButton button;

	public GenerateGui(GuiScreen parent) {
		parentScreen = parent;
	}

	@Override
	public void initGui() {
		Keyboard.enableRepeatEvents(true);
		field1 = new GuiTextField(1, fontRenderer, (int) (width * 0.5) - 150, 50, 300, 20);
		field1.setFocused(false);
		field1.setCanLoseFocus(true);
		field1.setMaxStringLength(64);
		field1.setText(I18n.format("text4.inf"));
		buttonList.add(this.button = new GuiButton(0, (int) (width * 0.75), (int) (height * 0.85), 80, 20,
				I18n.format("text2.inf")));
	}

	@Override
	public void drawScreen(int par1, int par2, float par3) {
		drawDefaultBackground();
		super.drawScreen(par1, par2, par3);
		drawCenteredString(fontRenderer, I18n.format("title.inf"), width / 2, 10, 0xFFFFFF);
		drawString(fontRenderer, I18n.format("text1.inf"), (int) (width * 0.5) - 150, 35, 0xFFFFFF);
		drawString(fontRenderer,
				String.format(I18n.format("text3.inf"), CommonProxy.path.getAbsolutePath()).substring(13,
						String.format(I18n.format("text3.inf"), CommonProxy.path.getAbsolutePath()).length()),
				(int) (width * 0.5) - 150, 75, 0xFFFFFF);
		field1.drawTextBox();
	}

	@Override
	protected void mouseClicked(int par1, int par2, int par3) {
		field1.mouseClicked(par1, par2, par3);
		try {
			super.mouseClicked(par1, par2, par3);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onGuiClosed() {
		Keyboard.enableRepeatEvents(false);
	}

	@Override
	protected void keyTyped(char par1, int par2) {
		if (field1.textboxKeyTyped(par1, par2))
			return;
		try {
			super.keyTyped(par1, par2);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void actionPerformed(GuiButton button) {
		if (button == this.button)
			mc.displayGuiScreen(parentScreen);
	}
}
